package com.buss.article.service.impl;
import com.buss.article.service.BnsArticleServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import com.buss.article.entity.BnsArticleEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
import java.io.Serializable;

@Service("bnsArticleService")
@Transactional
public class BnsArticleServiceImpl extends CommonServiceImpl implements BnsArticleServiceI {

	
 	public <T> void delete(T entity) {
 		super.delete(entity);
 		//执行删除操作配置的sql增强
		this.doDelSql((BnsArticleEntity)entity);
 	}
 	
 	public <T> Serializable save(T entity) {
 		Serializable t = super.save(entity);
 		//执行新增操作配置的sql增强
 		this.doAddSql((BnsArticleEntity)entity);
 		return t;
 	}
 	
 	public <T> void saveOrUpdate(T entity) {
 		super.saveOrUpdate(entity);
 		//执行更新操作配置的sql增强
 		this.doUpdateSql((BnsArticleEntity)entity);
 	}
 	
 	/**
	 * 默认按钮-sql增强-新增操作
	 * @param id
	 * @return
	 */
 	public boolean doAddSql(BnsArticleEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-更新操作
	 * @param id
	 * @return
	 */
 	public boolean doUpdateSql(BnsArticleEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-删除操作
	 * @param id
	 * @return
	 */
 	public boolean doDelSql(BnsArticleEntity t){
	 	return true;
 	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @return
	 */
 	public String replaceVal(String sql,BnsArticleEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{title}",String.valueOf(t.getTitle()));
 		sql  = sql.replace("#{content}",String.valueOf(t.getContent()));
 		sql  = sql.replace("#{area_id}",String.valueOf(t.getAreaId()));
 		sql  = sql.replace("#{group_id}",String.valueOf(t.getGroupId()));
 		sql  = sql.replace("#{theme_id}",String.valueOf(t.getThemeId()));
 		sql  = sql.replace("#{article_label}",String.valueOf(t.getArticleLabel()));
 		sql  = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
 		sql  = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
 		sql  = sql.replace("#{publisher_states}",String.valueOf(t.getPublisherStates()));
 		sql  = sql.replace("#{comments_num}",String.valueOf(t.getCommentsNum()));
 		sql  = sql.replace("#{browse_num}",String.valueOf(t.getBrowseNum()));
 		sql  = sql.replace("#{is_up}",String.valueOf(t.getIsUp()));
 		sql  = sql.replace("#{is_close}",String.valueOf(t.getIsClose()));
 		sql  = sql.replace("#{is_zambia}",String.valueOf(t.getIsZambia())); 
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
}